/* function renderCategroy(){
    axios.get ('/my/categroy/list').then(res =>{
        let {status,data}=res.data;
        if(status ===0){
            let str = '';
            data.forEach(item =>{
                str +=`<tr>
                <td>${item.name}</td>
                <td>${item.alias}</td>
                <td>
                  <button data-id="${item.id}" data-name="${item.name}" data-alias="${item.alias}" type="button" class="layui-btn layui-btn-xs">编辑</button>
                  <button data-id="${item.id}" type="button" class="del layui-btn layui-btn-xs layui-btn-danger">删除</button>
                </td>
              </tr>`
            })
            $('tbody').html(str)
        }

    })
}
renderCateGory();

// 删除
$('tbody').on('click','del',function(){
    let id = $(this).data('id');
    layer.confirm('你确定不要我了吗',function(index){
        axios.get (`/my/categroy?id=${id}`).then(res=>{
            let {staus,message}=res.data;
            if(status===0){
                layer.msg(message);
                renderCateGory();
            }
        })
        layer.close(index)
    })
})
let addIndex;
$('button:contains("添加类别")').on('click',function(){
    addIndex = laye.open({
        type:1,
        title:'添加类别',
        content:$('#api-add').html(),
        area:['500px','250px']
    })
})
$('body').on('submit','#add-form',function(e){
    e.preventDefault();
    let data = $(this).serialize();
    axios.post('/my/category/add',data).then(res =>{
        if(status===0){
            layer.msg(message);
            renderCategroy();
            layer.close(addIndex);
        }
    })
});
let aditIndex;
$('tbody').on('click','button:contains("编辑")',function(){
    let shuju  = $(this).data();
    editIndex = layer.open({
        type:1,
        title:'编辑类别',
        content:$('#tpl-edit').html(),
        area:['500px','250px'],
        success:function(){
            let form = layui.form;
            form,val('edit',shuju);
        }
    })
})
$('body').on('submit','#edit-form',function(e){
    e.praventDefault();
    $(this).serilize();
    axios.post('/my/category/update',data).then(res =>{
        let {status,message}=res.data;
        if(status===0){
            layer.msg(message);
            renderCategory();
            layer.close(editIndex)
        }
    })
})
initEditor();
axiou.get('/my/category/list').then(res =>{
    let {status,data}=res.data;
    if(status===0){
        let str ='';
        data.forEach(item =>{
            str +=`<option value="${item.id}">${item.name}</option>`;
        })
        $('select[name=cate_id]').append(str);
        let form = layer.form;
        form.render('select');
    }
});
var image =$('#image')
var option = {
    aspectRation:400/280,
    preview:'.img-preview'
}
image.cropper(options);
$('button:contains("选择封面")').click(function(){
    $('#file').trigger('click')
})
// 3. 图片切换的时候，更换剪裁区的图片
$('#file').change(function () {
  if (this.files.length > 0) {
    // 3.1) 找到文件对象
    var fileObj = this.files[0];
    // 3.2) 创建url
    var url = URL.createObjectURL(fileObj);
    // 3.3) 更换图片
    image.cropper('replace', url);
  }
});
$('form').on('submit',function(e){
    e.preventDefault();
    let fd = new FormData(this);
    fd.set('content', tinyMCE.activeEditor.getContent());
    let canvas = iage.cropper('getCroppedCanvas',{})
    
}) */
/* const fs =require('fs');
const http = require('http');
const servet = http.createServer();
server.on('request',(req,res)=>{
    let filename = req.url;
    if(filename==='/'){
        filename = '/index.html';
    }
    let url =new URL(filename,'http')
    let pathname = url.pathname;
    fs.access('.'+pathname,err=>{
       if(err){
        res.statusCode =404;
        res.end('Not Found!');
    }else {fs.readFile('.'+pathname,utf-8,(e,d)=>{
            if(e)throw e;
            res.end(d)
        })
    }

    })
})
server.listen(3006,()=>{
    console.log(启动了);
}) */
/* const fs = require('fs')
const http = require('http');
const server =http.createServer();
server.on('request',(req,res)=>{
// res.end('daojiahao')
if(req.url ==='/'){
    req.url ='/index.html'
}
let url = new URL(req.url,'http://www.xxd.com');
fs.access('.'+url.pathname, err=>{
    if(err){
        res.statusCode=404;
        res.end('Not Found!')

    }else{
        fs.readFile('.'+url.pathname,(e,d)=>{
            if(e)throw e;
            res.end(data)
        })
    }
})
})
server.listen(3006,()=>{
    console.log(123);
}) */
